package com.zy.openchat.util;

import android.graphics.Camera;
import android.graphics.Matrix;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.Transformation;

public class RedPacketAnim extends Animation {
    int center_X,center_Y;
    Camera camera = new Camera();

    @Override
    public void initialize(int width, int height, int parentWidth, int parentHeight) {
        super.initialize(width, height, parentWidth, parentHeight);
        center_X = width/ 2;
        center_Y = height / 2;
        setDuration(3000L);
        setInterpolator(new AccelerateInterpolator());
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        final Matrix matrix = t.getMatrix();
        camera.save();
        camera.rotateY(1080 * interpolatedTime);
        camera.getMatrix(matrix);
        matrix.preTranslate(-center_X, -center_Y);
        matrix.postTranslate(center_X, center_Y);
        camera.restore();
    }
}
